package sg.edu.nus.iss.team8s.vmcs.control;
/**
 * 
 * @author Nie XiaoYi
 *
 */
import java.io.IOException;

import sg.edu.nus.iss.team8s.vmcs.PropertyLoader.CashPropertyLoader;
import sg.edu.nus.iss.team8s.vmcs.PropertyLoader.DrinkPropertyLoader;
import sg.edu.nus.iss.team8s.vmcs.PropertyLoader.PropertyLoader;
import sg.edu.nus.iss.team8s.vmcs.beans.Environment;

public class MainController {

	private SimulationController simController;
	public MainController(){
		
	}
	public void start() throws IOException{
		
		initialize();
		
		//subscribe the controllers to store after initialization
		DispenseController.getInstance();
		MachineryController.getInstance();
		MaintenanceController.getInstance();
		TransactionController.getInstance();
		
		if(simController == null)
			simController = new SimulationController();
		simController.displaySimulationControlPanel();
		simController.SetSimulationActive(false);
	}
	
	private void initialize() throws IOException{
		Environment env = new Environment();
		env.initialize();
		String cashFile = env.getCashPropFile();
		String drinkFile = env.getDrinkPropFile();
		
		if(cashFile == null || drinkFile == null)
			return;
		
		PropertyLoader cpl = CashPropertyLoader.getInstance(cashFile);
		PropertyLoader dpl = DrinkPropertyLoader.getInstance(drinkFile);
		
		cpl.initialize();
		dpl.initialize();
		
		StoreController stoController = StoreController.getInstance(cpl,dpl);
		stoController.initialize();
	}
	
	public void closeDown(){
		StoreController storeController = StoreController.getInstance();
		storeController.closeDown();
	}
}
